package cn.com.connext.scrm.web.rest;

import cn.com.connext.scrm.domain.master.WriteOffCode;
import cn.com.connext.scrm.domain.master.ZnhjEntity;
import cn.com.connext.scrm.service.ScanCodeRecordImpl;
import cn.com.connext.scrm.service.WriteOffCodeService;
import cn.com.connext.scrm.service.dto.JsonResult;
import cn.com.connext.scrm.service.dto.WriteOffRecordDTO;
import cn.com.connext.scrm.service.dto.ZnhjOperation;
import cn.com.connext.scrm.service.mapper.ZnhjService;
import cn.com.connext.scrm.web.rest.vm.IsScanVM;
import cn.com.connext.scrm.web.rest.vm.ScanCodeRecordVM;
import cn.com.connext.scrm.web.rest.vm.WriteOffCodePageVM;
import cn.com.connext.scrm.web.rest.vm.WriteOffCodeVM;
import com.connext.common.web.rest.BaseResource;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 第三方调用接口
 */
@RestController
@RequestMapping("/api/writeoffcode/")
public class WriteOffCodeResource extends BaseResource {

    @Autowired
    private WriteOffCodeService wocService;

    public WriteOffCodeResource() {
        super("WriteOffCode");
    }

    /**
     * 新增核销码
     */
    @ApiOperation(value = "新增核销码", notes = "新增核销码")
    @PostMapping(value = "/add")
    public JsonResult add(@RequestBody WriteOffCodeVM wocv ){
        return  wocService.save(wocv);
    }

    /**
     * 新增核销码
     */
    @ApiOperation(value = "编辑核销码", notes = "编辑核销码")
    @PostMapping(value = "/edit")
    public JsonResult edit(@RequestBody WriteOffCodeVM wocv ){
        return  wocService.edit(wocv);
    }

    /**
     * 分页查询核销码列表
     */
    @ApiOperation(value = "分页查询核销码列表", notes = "分页查询核销码列表")
    @PostMapping(value = "/findByPage")
    public JsonResult findByPage(@RequestBody WriteOffCodePageVM wocv ){
        JsonResult result = new JsonResult();
        try{
            Page<WriteOffCode> page = wocService.findByPage(wocv);
            result.setData(page);
            result.setState(0);
        } catch (Exception e) {
            result.setState(-1);
            result.setMessage("查询失败");
        }
        return result;
    }

    /**
     * 删除核销码
     */
    @ApiOperation(value = "删除核销码", notes = "删除核销码")
    @PostMapping(value = "/delete")
    public JsonResult delete(@RequestBody WriteOffCodeVM wocv ){
        return  wocService.delete(wocv);
    }

}

